package dev.ideas.funkyj.function;

import dev.ideas.funkyj.function.P;
import org.junit.Test;

import static dev.ideas.funkyj.support.PredicateSupport.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

/**
 */
public class AndOrNot {

    @Test public void t() {
        final P<Integer> p1 = even.and(in(range(1, 4)));

        assertEquals("even and in [1 - 4]", p1.toString());
        assertTrue(p1.apply(2));
        assertFalse(p1.apply(1));
        assertFalse(p1.apply(6));

        final P<Integer> notP1 = p1.not();
        final P<Integer> notP1_ = not(p1);
        assertEquals("not (even and in [1 - 4])", notP1_.toString());
        assertEquals("not (even and in [1 - 4])", notP1.toString());
        assertFalse(notP1.apply(2));
        assertTrue(notP1.apply(1));
        assertTrue(notP1.apply(6));

        final P<Integer> p2 = odd.or(even.and(in(2, 4)));
        assertEquals("odd or (even and in [2, 4])", p2.toString());
        assertTrue(p2.apply(1));
        assertTrue(p2.apply(2));
        assertFalse(p2.apply(6));

        final P<Integer> p3 = odd.or(even).and(in(range(1, 10)));
        assertEquals("odd or (even) and in [1 - 10]", p3.toString());
        assertTrue(p3.apply(1));
        assertTrue(p3.apply(2));
        assertFalse(p3.apply(11));


    }
}
